<?php

namespace IDock\Insurance\LIHI\Response;

use IDock\Http\Response;
use IDock\Insurance\LIHI\Response\AllLIHIResponse;
use IDock\Printer\PremiumUnderwritingPrinter;

class UnderwritingResponse extends AllLIHIResponse
{

    /**
     * @var PremiumUnderwritingPrinter $printer
     */
    public $printer = PremiumUnderwritingPrinter::class;

    public function printerInit(): Response
    {
        $data = $this->getBody()['result'] ?? [];
        $code = $data['underWriteFlag'] ?? '';
        $code1 = $data['proposalStatus'] ?? '';
        if(!in_array($code,['2','7','50','51','8','9','10'])){
            $code = $code1;
        }
        $this->printer->inquiryNo = '';
        $this->printer->ciInquiryNo = $data['proposalMTPLNo'] ?? '';
        $this->printer->biInquiryNo = $data['proposalNo'] ?? '';
        $this->printer->messageTip = $data['message'] ?? '';

        //下发
        if (in_array($code,['2','7'])) {
            $this->printer->statusCode = 'U4';
        }
        //成功
        if (in_array($code,['50','51','8']))  {
            $this->printer->statusCode = 'U1';
        }
        //人工
        if (in_array($code,['9','10'])) {
            $this->printer->statusCode = 'U3';
        }

        return $this;
    }
}
